package org.lab.data;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.lab.io.IDownloader;
import org.lab.io.reader.DataCSVReader;

public class MarketData {
	private static Map<String, Ticker> tickers = new HashMap<String, Ticker>();
	
	public static void register(String name, IDownloader downloader) {
		Ticker ticker = new Ticker(downloader);
		if (!tickers.containsKey(name)) {
			ticker.importData();
			tickers.put(name, ticker);
		} else {
			System.out.println("Ticker already defined.");
		}
	}
	
	public static void register(String name, String filename) {
		IDownloader downloader = new DataCSVReader(filename);
		MarketData.register(name, downloader);
	}
	
	public static List<Quote> getData(String name) {
		if (tickers.containsKey(name)) {
			Ticker ticker = (Ticker)tickers.get(name);
			return ticker.getQuotes();
		} else {
			System.out.println("Ticker not defined.");
			return null;
		}
	}
	
	public static Ticker getTicker(String name){
		if (tickers.containsKey(name)) {
			return (Ticker)tickers.get(name);
		} else {
			System.out.println("Ticker not defined.");
			return null;
		}
	}
	
	/*public static Quote getData(String name, Date date) {
		if (tickers.containsKey(name)) {
			Ticker ticker = (Ticker)tickers.get(name);
			return ticker.getQuotes().get(date);
		} else {
			System.out.println("Ticker not defined.");
			return null;
		}
	}*/
	
}
